import express from 'express';
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

if (!process.env.DATA_BASE_URI || !process.env.PORT) {
	console.error('请设置启动端口或数据库!');
	process.exit(1);
}

app.use(require('./router/index'));

import mongoose from 'mongoose';
mongoose
	.connect(process.env.DATA_BASE_URI!)
	.then(() => {
		app.listen(process.env.PORT!, () => {
			console.log(`服务已启动 | 端口:${process.env.PORT}`);
		});
	})
	.catch((err) => {
		console.log('数据库连接失败: ', err?.message);
	});
